import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QMenuBar, QMenu, QTreeView
from PyQt5 import uic
from Connect import RedisConnect


class RedisDesktop(QMainWindow):
    def __init__(self):
        super(RedisDesktop, self).__init__()
        uic.loadUi("../ui/RedisDesktop.ui", self)

        # 左侧树结构
        self.leftTree: QTreeView
        self.leftTree.setHeaderHidden(True)

        # 获取菜单栏
        menubar = self.findChild(QMenuBar)
        # 获取菜单栏下的菜单
        menu = menubar.findChild(QMenu)
        # 获取菜单下的action
        actions = menu.actions()

        for action in actions:
            action.triggered.connect(self.open_connect)

        self.redis_connect = RedisConnect(self)

    # 打开连接页面
    def open_connect(self):
        self.setEnabled(False)
        action: QAction = self.sender()
        object_name = action.objectName()
        if 'actionnew' == object_name:
            self.redis_connect.show()
            self.redis_connect.setEnabled(True)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    redis_desktop = RedisDesktop()
    redis_desktop.show()
    sys.exit(app.exec_())
